package njust.csc.aeapi.controller

import njust.csc.aeapi.entity.SdkFilter
import njust.csc.aeapi.entity.UrlFilter
import njust.csc.aeapi.model.MessageModel
import njust.csc.aeapi.service.SdkFilterService
import njust.csc.aeapi.service.UrlFilterService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.*

/**
 * @Author ZhouHang
 * @Date 24/8/12 周一
 */
@RestController
@RequestMapping("/api/sdk_filter")
class SdkFilterController @Autowired constructor(
    private val sdkFilterService: SdkFilterService
) {
    @GetMapping("/find_all")
    fun findAll(): List<SdkFilter> {
        return sdkFilterService.findAll()
    }

    @PostMapping("/add")
    fun addOne(sdkFilter: SdkFilter): MessageModel {
        sdkFilterService.saveOrUpdate(sdkFilter)
        return MessageModel(
            code = 2000,
            message = "Success"
        )
    }

    @PutMapping("/update")
    fun updateOne(sdkFilter: SdkFilter): MessageModel {
        sdkFilterService.saveOrUpdate(sdkFilter)
        return MessageModel(
            code = 2000,
            message = "Success"
        )
    }

    @DeleteMapping("/delete/{id}")
    fun deleteOne(@PathVariable("id") id: Int): MessageModel {
        sdkFilterService.delete(id)
        return MessageModel(
            code = 2000,
            message = "Success"
        )
    }
}

@RestController
@RequestMapping("/api/url_filter")
class UrlFilterController @Autowired constructor(
    private val urlFilterService: UrlFilterService
) {
    @GetMapping("/find_all")
    fun findAll(): List<UrlFilter> {
        return urlFilterService.findAll()
    }

    @PostMapping("/add")
    fun addOne(urlFilter: UrlFilter): MessageModel {
        urlFilterService.saveOrUpdate(urlFilter)
        return MessageModel(
            code = 2000,
            message = "Success"
        )
    }

    @PutMapping("/update")
    fun updateOne(urlFilter: UrlFilter): MessageModel {
        urlFilterService.saveOrUpdate(urlFilter)
        return MessageModel(
            code = 2000,
            message = "Success"
        )
    }

    @DeleteMapping("/delete/{id}")
    fun deleteOne(@PathVariable("id") id: Int): MessageModel {
        urlFilterService.delete(id)
        return MessageModel(
            code = 2000,
            message = "Success"
        )
    }
}
